package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @Author Justin Parker
 * @Date 2024/7/16 0016 14:30
 * @Version 1.0
 */
public class WriteStringDemo01 {
    /*
      文本的字符串写入文件中
     */
    public static void main(String[] args) throws IOException {
        String line = "我爱java";
        // 创建文件输出流对象
        FileOutputStream fos = new FileOutputStream("./f1.text", true);
        // 将字符串转换为字节数组
         byte[] data = line.getBytes(StandardCharsets.UTF_8);
         fos.write(data);
        line="喜欢大雷";
        fos.write(line.getBytes(StandardCharsets.UTF_8));
        System.out.println("写入成功");
        //释放资源
        fos.close();


    }
}
